#AilAg1 = login-ready voice
#AilAg2 = login-ready 
#AilAg3 = login-ready 
#AilAg4 = login-notready
#AilAg5 = logout


def mixed_1():
  """Email and voice interactions"""
  emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
  recEmails = AilAg3.AcceptEmail([emailMsg])

  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()
  AilAg3.ReleaseCall()
  if recEmails:
    AilAg3.MarkDoneEmail(emailMsg)

def mixed_2():
  """2 email and 1 voice interactions, agent replies emails"""
  emailMsg1 = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
  emailMsg2 = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
  recEmails = AilAg3.AcceptEmail([emailMsg1, emailMsg2])
  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()
  if recEmails:
    replyEmailIntr1 = AilAg3.ReplyEmail(emailMsg1)
    AilAg3.MarkDoneEmail(emailMsg1)
    replyEmailIntr2 = AilAg3.ReplyEmail(emailMsg2)
    AilAg3.MarkDoneEmail(emailMsg2)
  AilAg3.ReleaseCall()    
  Customer1.GetEmails([replyEmailIntr1,replyEmailIntr2])


def mixed_3():
  """Agent not ready voice, ready email, accepts email, sets ready voice, accepts call"""
  AilAg3.SetNotReady(["voice"])
  try:
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    recEmails = AilAg3.AcceptEmail([emailMsg])
    Customer1.MakeCall(CDN1) #call stays in queue
    AilAg3.SetReady(["voice"])
    AilAg3.AnswerCall()
    Customer1.ReleaseCall() 
    if recEmails:
      AilAg3.MarkDoneEmail(emailMsg)
  finally:
    AilAg3.SetReady(["voice"])
  

def mixed_4():
  """Agent not ready email, ready voice, accepts call, sets ready email, accepts email"""
  AilAg3.SetNotReady(["email"])
  try:
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    Customer1.MakeCall(CDN1)
    AilAg3.AnswerCall()    
    AilAg3.SetReady(["email"])
    recEmails = AilAg3.AcceptEmail([emailMsg])
    Customer1.ReleaseCall() 
    if recEmails:
      AilAg3.MarkDoneEmail(emailMsg)
  finally:
    AilAg3.SetReady(["email"])
    
def mixed_5():
  """Agent not ready all medias, set ready, accepts call and email"""
  AilAg3.SetNotReady() # all media types
  try:
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
    Customer1.MakeCall(CDN1) #call stays in queue
    AilAg3.SetReady() # all media types
    AilAg3.AnswerCall()
    recEmails = AilAg3.AcceptEmail([emailMsg])  
    if recEmails:
      AilAg3.MarkDoneEmail(emailMsg)  
    Customer1.ReleaseCall() 
  finally:
    AilAg3.SetReady()# all media types
    
    
def mixed_6():
  """Email, chat and voice interactions"""
  emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")
  recEmails = AilAg3.AcceptEmail([emailMsg])
  chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
  agChat = AilAg3.AcceptChat()
  Customer1.GetChatMessage("joined")
  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()
  AilAg3.MarkDoneChat(agChat)
  Customer1.GetChatMessage("left")  
  AilAg3.ReleaseCall()
  if recEmails:
    AilAg3.MarkDoneEmail(emailMsg)
    
def mixed_7():
  """Agent not ready voice, ready chat, accepts chat, sets ready voice, accepts call"""
  AilAg3.SetNotReady(["voice"])
  try:
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    agChat = AilAg3.AcceptChat()
    Customer1.GetChatMessage("joined")    
    Customer1.MakeCall(CDN1) #call stays in queue
    AilAg3.SetReady(["voice"])
    AilAg3.AnswerCall()
    Customer1.ReleaseCall() 
    AilAg3.MarkDoneChat(agChat)
    Customer1.GetChatMessage("left")  
  finally:
    AilAg3.SetReady(["voice"]) 
    
    
def mixed_8():
  """Agent not ready chat, ready voice, accepts call, sets ready chat, accepts chat"""
  AilAg3.SetNotReady(["chat"])
  try:
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    Customer1.MakeCall(CDN1)
    AilAg3.AnswerCall()    
    AilAg3.SetReady(["chat"])
    agChat = AilAg3.AcceptChat()
    Customer1.ReleaseCall() 
    AilAg3.MarkDoneChat(agChat)
    Customer1.GetChatMessage("left")  

  finally:
    AilAg3.SetReady(["chat"])  
    
def mixed_9():
  """Agent not ready chat, email, ready voice, accepts call, sets ready chat, accepts chat, sets ready email, accepts email"""
  AilAg3.SetNotReady(["chat"])
  AilAg3.SetNotReady(["email"])
  try:
    emailMsg = Customer1.SendEmail(GetOption("ESAddr"), text = "Hello, AILAgent")  
    chat = Customer1.StartChat(GetOption("WebHost"), GetOption("ChatScript"))
    Customer1.MakeCall(CDN1)
    AilAg3.AnswerCall()    
    AilAg3.SetReady(["chat"])
    agChat = AilAg3.AcceptChat()
    AilAg3.SetReady(["email"])
    recEmails = AilAg3.AcceptEmail([emailMsg])
    
    Customer1.ReleaseCall() 
    AilAg3.MarkDoneChat(agChat)
    Customer1.GetChatMessage("left")
    if recEmails:
      AilAg3.MarkDoneEmail(emailMsg)    

  finally:
    AilAg3.SetReady(["chat"])    
    AilAg3.SetReady(["email"])

def mixed_10():
  """Agent not ready chat, email, ready voice, accepts call"""
  AilAg3.SetNotReady(["chat"])    
  AilAg3.SetNotReady(["email"])
  try:
    Customer1.MakeCall(CDN1)
    AilAg3.AnswerCall()    
    Customer1.ReleaseCall() 
  finally:
    AilAg3.SetReady(["chat"])    
    AilAg3.SetReady(["email"])


def mixed_11():
  """Agent  ready chat, email, ready voice, accepts call"""
  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()    
  Customer1.ReleaseCall() 

def mixed_12():
  """Agent not ready voice, ready voice, accepts call"""
  AilAg3.SetNotReady(["voice"])
  Customer1.MakeCall(CDN1)
  AilAg3.SetReady(["voice"])
  AilAg3.AnswerCall()    
  Customer1.ReleaseCall() 

def mixed_13():
  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()    
  Customer1.ReleaseCall() 
  AilAg3.Logout()
  AilAg3.Login()
  AilAg3.SetReady()
  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()    
  Customer1.ReleaseCall() 

def mixed_14():
  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()    
  Customer1.ReleaseCall() 
  AilAg3.SetNotReady()
  AilAg3.SetReady()
  Customer1.MakeCall(CDN1)
  AilAg3.AnswerCall()    
  Customer1.ReleaseCall() 

